#!/usr/bin/env python3

import json
import os
import subprocess
import sys
from os import path
import tempfile
from subprocess import Popen, PIPE, DEVNULL
import shutil

import plx

if len(sys.argv) < 3:
    print("Usage: plx-installpck <package_name> <install_path>")
    sys.exit(1)

if os.geteuid() != 0:
    print("Permission Denied")
    sys.exit(1)

if not plx.lock():
    print("Failed lock package db")
    sys.exit(1)

pck = sys.argv[1]
inst_path = sys.argv[2]

try:
    plx.install_package(pck, inst_path)
except Exception as err:
    print("Installation Error: {0}".format(err))
    plx.unlock()
    sys.exit(1)

plx.unlock()
